using System;
using System.ComponentModel.Composition;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using SeventhSenseSystems.HighFlyingPm.Business.Entities;
using SeventhSenseSystems.HighFlyingPm.Business.Models;

namespace WebBusiness.Controllers
{   
	[Export("adminissuestatus",typeof(IController))]
	[PartCreationPolicy(CreationPolicy.NonShared)]
	public class AdminIssueStatusController : Controller
	{
		private readonly IIssueStatusRepository issuestatusRepository;

		[ImportingConstructor]
		public AdminIssueStatusController(IIssueStatusRepository issuestatusRepository)
		{
			this.issuestatusRepository = issuestatusRepository;
		}

		//
		// GET: /AdminIssueStatus/

		public ViewResult Index()
		{
			return View(issuestatusRepository.All);
		}

		//
		// GET: /AdminIssueStatus/Details/5

		public ViewResult Details(System.Guid id)
		{
			return View(issuestatusRepository.Find(id));
		}

		//
		// GET: /AdminIssueStatus/Create

		public ActionResult Create()
		{
			return View();
		} 

		//
		// POST: /AdminIssueStatus/Create

		[HttpPost]
		public ActionResult Create(IssueStatus issuestatus)
		{
			if (ModelState.IsValid) {
				issuestatus.Id = Guid.NewGuid();
				issuestatusRepository.Add(issuestatus);
				issuestatusRepository.Save();
				return RedirectToAction("Index");
			} else {
				return View();
			}
		}
		
		//
		// GET: /AdminIssueStatus/Edit/5
 
		public ActionResult Edit(System.Guid id)
		{
			 return View(issuestatusRepository.Find(id));
		}

		//
		// POST: /AdminIssueStatus/Edit/5

		[HttpPost]
		public ActionResult Edit(IssueStatus issuestatus)
		{
			if (ModelState.IsValid) {
				issuestatusRepository.Edit(issuestatus);
				issuestatusRepository.Save();
				return RedirectToAction("Index");
			} else {
				return View();
			}
		}

		//
		// GET: /AdminIssueStatus/Delete/5
 
		public ActionResult Delete(System.Guid id)
		{
			return View(issuestatusRepository.Find(id));
		}

		//
		// POST: /AdminIssueStatus/Delete/5

		[HttpPost, ActionName("Delete")]
		public ActionResult DeleteConfirmed(System.Guid id)
		{
			issuestatusRepository.Delete(issuestatusRepository.Find(id));
			issuestatusRepository.Save();

			return RedirectToAction("Index");
		}

		protected override void Dispose(bool disposing)
		{
			if (disposing) {
				issuestatusRepository.Dispose();
			}
			base.Dispose(disposing);
		}
	}
}

